package com.idis.dbApp.controller;

import com.idis.dbApp.mapper.PersonMapper;
import com.idis.entity.person;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by Ming on 2018/1/29.
 */
@RestController
@RequestMapping("/person")
@Api(tags = "人员信息接口")
public class PersonController {

    @Autowired
    PersonMapper personMapper;

    @ApiOperation("获取所有人员信息")
    @GetMapping("/all")
    public List<person> findAll(){
        return personMapper.findAll();
    }

    @ApiOperation("添加新的人员信息")
    @PostMapping("/save")
    public Integer save(@ApiParam("人员信息")@RequestBody person person){
        return personMapper.insert(person);
    }

    @PostMapping("/updatenotnull")
    @ApiOperation("更新非空人员信息")
    public Integer updateNotNull(@ApiParam("人员信息（若某属性不需要更新则置空该属性），ID必须")@RequestBody person person){
        return personMapper.updateByPrimaryKeySelective(person);
    }

    @ApiOperation("更新人员信息")
    @PostMapping("/update")
    public Integer update(@ApiParam("人员信息，ID必须")@RequestBody person person){
        return personMapper.updateByPrimaryKey(person);
    }

    @ApiOperation("根据属性查询人员")
    @PostMapping("/findbyproperty")
    public List<person> findByProperty(@ApiParam("要搜索的人员信息属性(若对某属性无搜索要求则置空)")@RequestBody person person){
        return personMapper.findByProperty(person);
    }

    @ApiOperation("根据ID删除人员信息")
    @PostMapping("/delete")
    public Integer delete(@ApiParam("人员信息(需要且仅需要ID)")@RequestBody person person){
        return personMapper.deleteByPrimaryKey(person.getId());
    }


}
